package graduate.cslg.com.universityshopping.mainPage;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toolbar;

import java.util.List;

import graduate.cslg.com.universityshopping.R;
import graduate.cslg.com.universityshopping.entity.ClassInfo;

public class ScorePostActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText userAccount;
    private Spinner classId;
    private EditText classScore;
    private Button submitButton;
    private String classNo[];
    private String getClassNo;
    private String getUserAccount;
    private String getUserScore;
    private List<ClassInfo> mClassInfos;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_score_post);

        initViews();

        for (int i = 0; i < mClassInfos.size(); i++) {
            classNo[i] = mClassInfos.get(i).getClass_id();
        }
        ArrayAdapter<String> id_adapter = new ArrayAdapter<>(this,
                android.R.layout.simple_spinner_dropdown_item,classNo);
        classId.setAdapter(id_adapter);
        classId.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                getClassNo = classNo[position];
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
    }

    private void initViews() {
        userAccount = findViewById(R.id.stu_account);
        classId = findViewById(R.id.class_id);
        classScore = findViewById(R.id.stu_score);
        submitButton = findViewById(R.id.submit_button);
        submitButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.submit_button:
                getUserAccount = userAccount.getText().toString();
                getUserScore = classScore.getText().toString();
                if (getUserScore.length() != 0 && getUserAccount.length() != 0) {
                    postScoreInfo(getUserAccount, getClassNo, getUserScore);
                }
                break;
        }
    }

    private void postScoreInfo(String stuId, String classId, String score) {

    }

    private void getClassInfo() {

    }
}
